﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;

namespace Moneymatters
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += Application_ThreadException;
            
            MainForm mainForm = new MainForm();
            if (!mainForm.IsDisposed)
            {
                //Application.Run(new MainForm());
                Application.Run(mainForm);
            }
        }

        static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            if (e.Exception as System.Data.EntityException != null)
            {
                MessageBox.Show("There is a problem with your database connection settings. The application could not connect to the configured database. Please get in touch with your administrator to have this corrected. The application will exit after you click OK.", "Incorrect database connection configuration", MessageBoxButtons.OK, MessageBoxIcon.Error);
                
            }
            else
            {
                MessageBox.Show("The application encoutered a problem and cannot continue running further. Please get in touch with your administrator to have this corrected. The application will exit after you click OK.", "Problem running the application", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            Application.Exit();
        }
    }
}
